package com.yxw.springmvc.userBehavior.validator;

import com.yxw.springmvc.userBehavior.model.UserPwd;
import com.yxw.springmvc.userBehavior.security.AesCipher;
import com.yxw.springmvc.userBehavior.util.PasswordUtil;
import org.springframework.stereotype.Service;

import java.security.GeneralSecurityException;

/**
 * Created by hp on 2016/9/23.
 */
@Service
public class UserPwdValidatorService {
    public boolean checkUserPwd(String userCode,String pwd,String randomCode ,UserPwd userPwd){
        try {
            pwd = AesCipher.decrypt(randomCode, pwd);
            pwd = PasswordUtil.genMD5Password(userCode,pwd);
            if(userPwd.getUserPwd().equals(pwd)){
                return true;
            }
        } catch (GeneralSecurityException e) {
            e.printStackTrace();
        }
        return false;
    }
}
